package classes;

import java.util.ArrayList;

import competences.ECompetence;

import data.ECaracteristique;
import data.JetsDeSauvegarde;
import dons.EDons;
import dons.ETypesDons;

public abstract class Classe {
	
	protected int niveau;
	protected int bba;
	protected int jds[];
	protected int bonusCompetence;
	protected boolean besoinDon;
	
	protected ArrayList<ECaracteristique> caracFavorable;
	protected ArrayList<ECompetence> competenceDeClasse;
	protected ArrayList<ETypesDons> typesDons;

	protected Classe () {
		jds = new int[JetsDeSauvegarde.values().length];
		caracFavorable = new ArrayList<ECaracteristique> ();
		competenceDeClasse = new ArrayList<ECompetence> ();
		
		this.niveau = 0;
		
		ajoutCaracFavorables ();
		ajoutCompetencesDeClasse ();
		levelUp ();
	}

	abstract protected void ajoutCaracFavorables ();
	abstract protected void ajoutCompetencesDeClasse ();
	
	abstract public void AdjustSort (int[] carac);

	public ArrayList<ECompetence> getCompetenceDeClasse () {
		return competenceDeClasse;
	}
	
	public int getNiveau() {
		return niveau;
	}

	public int getBba() {
		return bba;
	}

	public int[] getJdS() {
		return jds;
	}

	public int getBonusCompetence() {
		return bonusCompetence;
	}
	
	public boolean isCaracFavorable(ECaracteristique carac) {
		return caracFavorable.contains(carac);
	}
	
	public ArrayList<ETypesDons> getTypesDons () {
		return typesDons;
	}
	
	abstract public void levelUp ();
	
	protected void setBBACombattant () {
		bba = niveau;
	}
	
	protected void setBBASemiCombattant () {
		bba = niveau*3/4;
	}
	
	protected void setBBANonCombattant () {
		bba = niveau/2;
	}
	
	protected void setJdS (JetsDeSauvegarde jdsFavorable) {
		for (JetsDeSauvegarde j : JetsDeSauvegarde.values()) {
			if (j == jdsFavorable) {
				jds[j.ordinal()] = 2 + niveau/2;
			}
			else {
				jds[j.ordinal()] = niveau/3;
			}
		}
	}
	
	protected void setJdS (JetsDeSauvegarde jdsFavorable1, JetsDeSauvegarde jdsFavorable2) {
		for (JetsDeSauvegarde j : JetsDeSauvegarde.values()) {
			if ((j == jdsFavorable1) || (j == jdsFavorable2)){
				jds[j.ordinal()] = 2 + niveau/2;
			}
			else {
				jds[j.ordinal()] = niveau/3;
			}
		}
	}
	
	@Override
	public String toString() {
		String retour = "niveau=" + niveau + "\nbba=" + bba +"\n";
		String jdsTexte = "";
		
		for (JetsDeSauvegarde j : JetsDeSauvegarde.values()) {
			jdsTexte += ", " + j + " : "+jds[j.ordinal()];
		}
		
		retour +=jdsTexte.substring(jdsTexte.indexOf(" ")+1)+"\n";
		
		return retour;
	}
}
